package com.dfbz.demo01;

import java.util.TreeMap;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo06_TreeMap {
    public static void main(String[] args) {
        TreeMap<Goods, String> treeMap = new TreeMap<>();

        treeMap.put(new Goods("神舟战神笔记本", 8888.8D), "神舟");
        treeMap.put(new Goods("小米Pro15笔记本", 5899.0D), "小米");
        treeMap.put(new Goods("华硕无畏", 4899.0D), "华硕");

        System.out.println(treeMap);

    }
}

class Goods implements Comparable<Goods> {
    private String name;
    private Double price;


    @Override
    public int compareTo(Goods goods) {
//        return (int) (this.getPrice() - goods.getPrice());
        return (int) (goods.getPrice()- this.getPrice() );
    }


    public Goods() {
    }

    public Goods(String name, Double price) {
        this.name = name;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return "Goods{" +
                "name='" + name + '\'' +
                ", price=" + price +
                '}';
    }

}